<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>登入账号</title>
		<link rel="stylesheet" href="${webroot}/static/plugins/user/css/index_style.css" />
		<script src="${webroot}/static/plugins/user/js/jquery-1.7.1.min.js"></script>
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<script type="text/javascript" src="${webroot}/static/plugins/layui/layui.js"></script>
		<link rel="stylesheet" href="${webroot}/static/plugins/layui/css/layui.css">
		<!–[if lt IE 9]>
			<script src=”http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js”></script>
		<![endif]–>

		<script>
            var phoneWidth = parseInt(window.screen.width);
            var phoneHeight = parseInt(window.screen.height);
            var phoneScale = phoneWidth/460;//除以的值按手机的物理分辨率
            var phonheight = phoneHeight/200;
            var ua = navigator.userAgent;
            if (/Android (\d+\.\d+)/.test(ua)) {
                var version = parseFloat(RegExp.$1);
                // andriod 2.3
                if (version > 2.3) {
                    document.write('<meta name="viewport" content="width=device-width,initial-scale='+phoneScale+',minimum-scale='+phoneScale+',maximum-scale='+phoneScale+',user-scalable=no">');
                    // andriod 2.3以上
                } else {
                    document.write('<meta name="viewport" content="width=device-width,user-scalable=no">');
                }
                // 其他系统
            } else {
                document.write('<meta name="viewport" content="width=device-width, initial-scale='+phoneScale+',minimum-scale='+phoneScale+',maximum-scale ='+phoneScale +',user-scalable=no,">');
            }
		</script>

	</head>
	<body>
		<div class="register"  id="fontset">
			<table cellspacing="0" cellpadding="0" border="1">
				<tr>
					<td style=" margin-left:20px;width:220px;  text-align: center "colspan="2";  ><h3 style="font-weight: bold;">长沙市金融办</br>非法经营案个人资金返回查询系统</h3></td>
				</tr>
				<tr>
					<td>姓名：</td>
					<td><input type="text"  name="user_name" required="required" lay-verType="tips" lay-verify="required" placeholder="请输入用户名称" autocomplete="off" class="layui-input" /></td>
				</tr>
				<tr>
					<td>身份证号码：</td>
					<td><input type="text" name="id_card" required="" lay-verType="tips" lay-verify="identity|number" placeholder="请输入身份证" autocomplete="off" class="layui-input" /></td>
				</tr>
				<tr>
					<td>手机号码：</td>
					<td><input type="text" name="phone"  lay-verType="tips" lay-verify="required|phone" placeholder="请输入手机号" autocomplete="off" class="layui-input"/></td>
				</tr>
				<tr>
					<td>验证码：</td>
					<td>
						<input type="code" class="re_yan" placeholder="请输入验证码" name="code" /><input type="button" value="获取验证码" class="re_yan_btn obtain generate_code" id="gain"  />
						<span class="cuo">请输入正确的验证码</span>
					</td>
				</tr>
				<tr>
					<td></td>
					<td><input type="button" value="立即登录" class="xu_show" id="login" ></input></td>
				</tr>
			</table>
		</div>


		<script type="text/javascript">
			layui.use(['layer','form'],function () {
			    var layer = layui.layer,
				form = layui.form;
            });
			$(function () {
			    $("#login").click(function () {
			        var identity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
			        var tel  = /^1\d{10}$/;
                    var user_name = $("input[name='user_name']").val();
                    var id_card = $("input[name='id_card']").val();
                    var phone = $("input[name='phone']").val();
                    var code = $("input[name='code']").val();
                    code = code.toLowerCase();
					var flag = true;
                    if (user_name == ""){
                        flag = false;
                        layer.msg("用户名不能为空!");
					} else if (id_card == ""){
                        flag = false;
                        layer.msg("身份证不能为空!");
                    } else if(!identity.test(id_card)) {
                        flag = false;
                        layer.msg("请输入正确的身份证!");
                    } else if (phone == ""){
                        flag = false;
                        layer.msg("手机号不能为空!");
                    } else if(!tel.test(phone)) {
                        flag = false;
                        layer.msg("请输入正确的手机号!");
                    } else if (code == ""){
                        flag = false;
                        layer.msg("验证码不能为空!");
                    }
                  	if (flag){
                        $.ajax({
                            url: 'front/user.json',
                            type: 'post',
                            data: {user_name:user_name, id_card:id_card,phone:phone,code:code},
                            dataType: 'json'
                            ,success: function (data) {
                                if (data.code == 200){
                                    layer.msg("登入成功!");
                                    //登入成功跳转页面
                                    //生成随机数
                                    var x = 12;
                                    var y = 0;
                                    var rand = parseInt(Math.random() * (x - y + 1) + y);
                                    window.location.href="front/skip.json?id="+rand;
                                } else if (data == "验证码错误"){
                                    layer.msg("验证码错误!");
                                } else {
                                    layer.msg("登入失败，请输入正确的信息!");
                                }
                            }
                            ,error: function (data) {
                                layer.msg("验证码错误!");
                            }

                        })
					}
                });
                //倒计时
                var countdown=60;
                function settime(val) {
                    if (countdown == 0) {
                        val.removeAttribute("disabled");
                        val.value="获取验证码";
                        countdown = 60;
                        return false;
                    } else {
                        val.setAttribute("disabled", true);
                        val.value="重新发送(" + countdown + ")";
                        countdown--;
                    }
                    setTimeout(function() {
                        settime(val);
                    },1000);
                };

				$("#gain").click(function () {
				    var tel  = /^1\d{10}$/;
                    var phone = $("input[name='phone']").val();
                    var user_name = $("input[name='user_name']").val();
                    if (phone == ""){
                        layer.msg("手机号不能为空!");
                    }else if (!tel.test(phone)){
                        layer.msg("请输入正确的手机号");
                    }else {
                        settime(this);
                        $.ajax({
                            url: 'front/auth.json',
                            type: 'post',
                            data: {phone:phone,user_name:user_name},
                            dataType: 'json'
                            ,success: function (data) {
                                if (data.code == 200){
                                    layer.msg("发送成功!");
                                    settime(this)
                                } else {
                                    layer.msg("发送失败!");
                                    countdown = 0;
                                    settime(this)
                                }
                            }
                            ,error: function (data) {
                                layer.msg("发送失败!");

                            }

                        })

                    }

                });


            })
		</script>


	</body>
</html>
